<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
</head>
<body>
	<div id="app">
		<cpn></cpn>
	</div>
	<template id="cpn">
		<div>
			我是cpn组件
			<ccpn></ccpn>
		</div>
	</template>
	<template id="ccpn">
		<div>
			我是子组件
			<button @click="btnClick">按钮</button>
		</div>
	</template>
	<script src="../js/vue.js"></script>
	<script>
		const app = new Vue({
			el: '#app',
			data: {
				message: '你好啊Vue'
			},
			components: {
				cpn: {
					template: '#cpn',
					data(){
						return {
							name: '我是cpn的name'
						}
					},
					components: {
						ccpn: {
							template: '#ccpn',
							methods: {
								btnClick(){
									//  $parent  为了组件的复用性 子访问父 用的少
									console.log(this.$parent.name)
									//  $root  访问根组件 用的少
									console.log(this.$root.message)
								}
							}
						}
					}
				}
			}
		})
	</script>
</body>
</html>